import 'package:flutter/material.dart';
import 'package:terminal_flutter_demo/pages/base_widget_page.dart';
import 'package:terminal_flutter_demo/pages/button_type_page.dart';
import 'package:terminal_flutter_demo/pages/card_circle_aspect_page.dart';
import 'package:terminal_flutter_demo/pages/column_row_page.dart';
import 'package:terminal_flutter_demo/pages/grid_view_page.dart';
import 'package:terminal_flutter_demo/pages/list_view_page.dart';
import 'package:terminal_flutter_demo/pages/stack_align_page.dart';
import 'package:terminal_flutter_demo/pages/wrap_page.dart';

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(
        primaryColor: Colors.blue,
      ),
      home: const MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  final switchTitle = '切换';

  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int showIndex = 0;

  List<Widget> widgets = [];

  @override
  void initState() {
    super.initState();
    widgets = [
      const BaseWidget(),
      ListViewPage(),
      ListViewResPage(),
      GridViewPage(),
      ColumnRowPage(),
      const StackAlignPage(),
      CardCircleAspect(),
      const ButtonTypePage(),
      const WrapPage(),
    ];
  }

  Widget _getShowPage() {
    return widgets[showIndex];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Flutter')),
      body: _getShowPage(),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            showIndex++;
            if (showIndex > widgets.length - 1) {
              showIndex = 0;
            }
          });
        },
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(widget.switchTitle),
            // Text('$showIndex'),
            Text(widgets[showIndex].toString()),
          ],
        ),
      ),
    );
  }
}
